package com.juzipi.demo.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {


    public static String code(String string) {
        MessageDigest instance = null;
        try {
            instance = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        instance.update(string.getBytes());
        byte[] digest = instance.digest();
        int i;
        StringBuilder stringBuilder = new StringBuilder("");
        for (int offset = 0; offset < digest.length; offset++) {
            i = digest[offset];
            if (i < 0) {
                i += 256;
            }
            if (i < 16) {
                stringBuilder.append("0");
            }
            stringBuilder.append(Integer.toHexString(i));
        }
        return stringBuilder.toString();
    }

    //要加密的数据
    public static void main(String[] args) {
        System.out.println(code("xxxxxx"));

    }
}
